package com.xqiapp.webs.api;

import com.xqiapp.bean.Datax;
import com.xqiapp.bean.Resultx;
import com.xqiapp.entity.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by rwrwd7 on 2017/9/15.
 *
 * 用于测试的控制器
 *
 */
@RestController
@RequestMapping("/tests")
public class TestApi {

    /**
     * 使用方式
     * @param request
     * @return
     */
    @ApiOperation(value="get method", notes="get 数据")
    @RequestMapping(value="get",method = RequestMethod.GET)
    public Resultx get(HttpServletRequest request){
        Resultx resx = new Resultx();
        Datax data = new Datax(request);
        resx.setData(data);
        return resx;
    }

    @ApiOperation(value="post method", notes="post 数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String")
    })
    @RequestMapping(value="post", method=RequestMethod.POST)
    public Resultx post(HttpServletRequest request) {
        Resultx resx = new Resultx();
        Datax data = new Datax(request);
        User user = new User();
        user.setId(data.getString("id"));
        user.setUsername(data.getString("username"));
        data.put("user",user);
        resx.add("user",user);
        return resx;
    }



}
